1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
private void mDraw() { Canvas c = null; try { c = holder.lockCanvas(); if (c == null) return;
c.drawColor(Color.WHITE); paint.setAlpha(128); paint.setColor(getResources().getColor(R.color.circle_inner_color)); c.drawArc(region, -180, 180, true, paint);
{ paint.setShader(shader); paint.setAlpha(255); switch (align) { case left: c.drawArc(region, -180, (float) (180f * value / valueMax), true, paint); break; case center: c.drawArc(region, 270, (float) (90f * value / valueMax), true, paint); break; case right: c.drawArc(region, 0, (float) (-180f * value / valueMax), true, paint); break; } paint.setShader(null); paint.setAlpha(128); } { paint.setColor(getResources().getColor(R.color.circle_progress_point)); paint.setAlpha(255); c.save(); c.translate(region.centerX(), region.centerY()); c.drawCircle(0, 0, 10, paint); switch (align) { case left: c.rotate((float) (180f * value / valueMax + 90)); break; case center: c.rotate((float) (90f * value / valueMax + 180)); break; case right: c.rotate((float) (-180f * value / valueMax - 90)); break; }
Path p = new Path(); p.moveTo(-10, 0); p.lineTo(10, 0); p.lineTo(0, getHeight()); p.lineTo(-10, 0);
c.drawPath(p, paint);
c.restore(); paint.setAlpha(128); } { paint.setColor(Color.WHITE); String text = String.format("%.2f", Math.abs(value)); Rect bound = new Rect(); paint.getTextBounds(text, 0, text.length(), bound); bound.offset(-bound.width() / 2, 0); c.save(); c.translate(getWidth() / 2, getHeight() - 20); c.drawRect(bound, paint);
paint.setColor(Color.BLACK); c.drawText(text, 0, 0, paint); c.restore(); } } catch (Exception e) {
} finally { if (c != null) holder.unlockCanvasAndPost(c); }
}
|